﻿using Hotel.Model;
using Hotel.Model.admin;
using MD5Hash;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel.DAL
{
    public class adminDAL
    {
        public adminDAL(HotelConText hotelConText)
        {
            HotelConText = hotelConText;
        }

        public HotelConText HotelConText { get; }


        /// <summary>
        /// /管理员登录
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="userpwd">密码</param>
        /// <returns></returns>
        public dynamic Login(string username, string? userpwd)
        {
            try
            {

                var count = HotelConText.admins.Where(x => x.UserName == username).Count();
                if (count == 0)
                {
                    return -1;//用户不在
                }
                else
                {
                    var c = HotelConText.admins.Where(x => x.UserName == username && x.UserPwd == userpwd).Count();
                    if (c == 0)
                    {
                        return -2;//密码错误
                    }
                    else
                    {
                        var infor = HotelConText.admins.Where(x => x.UserName == username && x.UserPwd == userpwd).FirstOrDefault();
                        return infor;
                    }
                }


            }
            catch (Exception ex)
            {

                throw ex;
            }


        }



     









    }

}
